package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.EFoodcategory;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface GoryMapper {
    @Select("select * from e_foodcategory")
    List<EFoodcategory> queryGoryList();

    @Insert("insert e_foodcategory(id,name, foodCount) VALUES (#{id},#{name},#{count})")
    int insertGory(@Param("id")Long id,@Param("name")String name,@Param("count")Long count);

    @Delete("delete from e_foodcategory where id=${id}")
    int deleteGory(@Param("id")int id);

    @Update("update e_foodcategory set name=#{name},foodCount=#{count} where id=#{id}")
    int updateGory(@Param("name")String name,@Param("count")Long count,@Param("id")Long id);

    @Select("select count(0) from e_foodcategory")
    int queryGoryCount();

    @Select("select * from e_foodcategory where id = #{id}")
    EFoodcategory queryById(@Param("id")long category);

    /**
     * 检索出每个分类的所有菜品
     * @return
     */
    @Select("select * from e_foodcategory")
    @Results(value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(property = "foods",column = "id",many = @Many(select = "com.xuetang9.t9.hotel.mapper.EFoodMapper.selectByType",fetchType = FetchType.EAGER))
    })
    List<EFoodcategory> selectByFood();

    @Select("select name from e_foodcategory")
    List<String> queryGoryName();

    @Select("select sum(f.orderCount) from e_foodcategory as g join e_food as f where f.category = g.id group by g.id order by g.id")
    List<Integer> queryGoryOrder();
}
